package com.powernode.business.utils;

import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Component
public class CreateSnUtil {

    //生成时间
    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmssSSS");

    //生成随机数
    public static Random random = new Random();

    /**
     * 调用传进参数生成订单
     * 订单号特点
     * 随机数
     * 最好单调递增
     * @param prefix
     * @return
     */
    public String createSn(String prefix){
        //当前时间
        String format = sdf.format(new Date());
        //随机数
        int rdm = random.nextInt(900000) + 100000;
        return prefix + format + "_" + rdm;
    }
}
